package com.selfdriving.activity;

import java.util.ArrayList;

import net.tsz.afinal.annotation.view.ViewInject;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.selfdriving.R;
import com.selfdriving.adapter.DetailAdapter;
import com.selfdriving.bean.DetailEntity;
import com.selfdriving.utils.StringUtil;

public class GroupMessageActivity extends BaseActivity {
	@ViewInject(id = R.id.topBack, click = "topBack")
	ImageView topBack;

	@ViewInject(id = R.id.topText)
	TextView topText;

	@ViewInject(id = R.id.topRight, click = "topRight")
	Button topRight;

	@ViewInject(id = R.id.message_list)
	ListView talkView;
	
	@ViewInject(id=R.id.footer_et)
	EditText footer_et;
	
	@ViewInject(id=R.id.footer_send,click="footer_send")
	Button footer_send;

	private ArrayList<DetailEntity> list = null;
	
	private DetailAdapter adapter;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.message);
		list = new ArrayList<DetailEntity>();
		topText.setText("消息记录");
		topRight.setVisibility(View.GONE);
		DetailEntity d1 = new DetailEntity("我:", "2012-04-26", "刚我们决定要自驾游去庐山 老李你怎么看啊",
				R.layout.list_say_me_item);
		
		DetailEntity d2 = new DetailEntity("老李:", "2012-04-26", "没问题，前段时间一直很忙，都没有放松过",
				R.layout.list_say_he_item);
		
		DetailEntity d3 = new DetailEntity("老周:", "2012-04-26","是啊，老李上个星期可是大忙人呢", R.layout.list_say_he_item);
		
		DetailEntity d4 = new DetailEntity("我:", "2012-04-26", "那我们来讨论下路线吧",R.layout.list_say_me_item);
		
		DetailEntity d5 = new DetailEntity("老周:", "2012-04-26", "稍等，让我去看看前辈们的攻略 ",
				R.layout.list_say_he_item);
		
		DetailEntity d6 = new DetailEntity("我:", "2012-04-26", "好啊，我也去看看，等下我们互相分享一下",
				R.layout.list_say_me_item);
		
		DetailEntity d7 = new DetailEntity("老李:", "2012-04-26", "嗯  好的",
				R.layout.list_say_me_item);
		list.add(d1);
		list.add(d2);
		list.add(d3);
		list.add(d4);
		list.add(d5);
		list.add(d6);
		list.add(d7);
		adapter = new DetailAdapter(this, list);
		talkView.setAdapter(adapter);
	}
	
	public void topBack(View v){
		this.finish();
	}
	
	public void footer_send(View v){
		if(StringUtil.isNullOrEmpty(footer_et.getText().toString())){
			showToast("不能发送空消息");
		}
		DetailEntity detailEntity = new DetailEntity("我:", "2013-11-26", footer_et.getText().toString(), R.layout.list_say_me_item);
		list.add(detailEntity);
		footer_et.setText("");
		talkView.setAdapter(adapter);
		talkView.setSelection(list.size());
	}
}
